﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RMS.Utils.MVP;
using RMS.Web.Shell.View;
using RMS.DataAccess.Entities;
using RMS.DataAccess.Repositories;
using RMS.DataAccess.Common;

namespace RMS.Web.Shell.Presenter
{
    public class SearchInPatientPresenter : Presenter<ISearchInPatientView>
    {
        PatientsRepository _patientsRepository;

        public SearchInPatientPresenter(PatientsRepository patientsRepository)
        {
            _patientsRepository = patientsRepository;
        }

        public EntityResult<Patients> GetPationt(string patientName, int startindex, int Lenght)
        {
            string[] names = patientName.Split(' ');
            return _patientsRepository.Find(item =>
            {
                item.FirstName = names[0];
                if (names.Count() > 1)
                    item.FamilyName = names[1];
            },
                PatientsColumns.PatientID, startindex, Lenght);
        }

        public Patients GetPationt(int patientId)
        {
            return _patientsRepository.Find(item => { item.PatientID = patientId; }).Single();
        }

        public void deletePatient(int Id)
        {
            _patientsRepository.Delete(Id);
        }

    }
}
